package com.atguigu.amqp.controller;

import com.atguigu.amqp.bean.Order;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author : leimingchao
 * @date Date : 2021年12月18日 10:30
 */
@RestController
public class OrderController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping(value = "/create/order")
    public Order createOrder(Long skuId,Integer num,Integer memberId) {
        Order order = new Order(UUID.randomUUID().toString().replace("-", ""), skuId, num, memberId);
        rabbitTemplate.convertAndSend("","createOrder",order);

        rabbitTemplate.convertAndSend("user.order.delay.exchange","order_delay",order);
        return order;
    }
}
